﻿using UnityEngine;
using System.Collections;

public class TestCutWater : MonoBehaviour 
{
	public WaterType _waterType;
	public GameObject _water;
	public GameObject _cutPanle;

	public float minValue;
	public float maxValue;
	public float speed;

	public bool isButtom {
		get
		{
			return transform.localPosition.z == minValue;
		}
	}	//到底了
	public bool isTop
	{
		get
		{ 
			return transform.localPosition.z == maxValue;
		}
	}//到顶了
		
	public void RaiseMine()
	{
		var z = speed * (maxValue - minValue);
		var pos = transform.localPosition;
		pos.z += z;

		pos.z = Mathf.Clamp (pos.z, minValue, maxValue);

		transform.localPosition = pos;

//		if (!_water.activeInHierarchy)
//			_water.SetActive (true);
	}

	public void DownMine()
	{
		var z = speed * (maxValue - minValue);
		var pos = transform.localPosition;
		pos.z -= z;

		pos.z = Mathf.Clamp (pos.z, minValue, maxValue);

		transform.localPosition = pos;

//		if (isButtom) {
//			_water.SetActive (false);
//		}
	}

	public void CutPanle()
	{
		Plane splitPlane = new Plane (_cutPanle.transform.up, _cutPanle.transform.position);
		_water.SendMessage ("LeaveMainClip", splitPlane, SendMessageOptions.DontRequireReceiver);
	}

	void Update()
	{
		CutPanle ();
	}
}
